<?php
class Table extends Element{
	
	private $header;
	private $rows;
	private $rowCount = 0;
	
	public function __construct(){
		$this->headers = array();
		$this->rows = array();
	}
	
	public function add_header($head){
		$this->header = $head;
	}
	
	public function add_row($row){
		$this->rows[$this->rowCount++] = $row;
	}
	
	public function __toString(){
		
		$s = '<table>';
		if ($this->header){
			$s .= '<th>';
			foreach ($this->header as $cell){
				$s .= '<td>' . $cell .'<td>';
			}
			$s .= '</th>';
		}
		
		if ($this->rows){
			for ($i = 0; $i < $this->rowCount; $i++){
				$s .= '<tr>';
				foreach ($this->rows[$i] as $cell){
					if (trim($cell) != '' && $cell != "\n")
					$s .= '<td>' . $cell .'</td>';
				}
				$s .= '</tr>';
			}
		}
		$s .= '</table>';
		return $s;
	}
	
}
?>